package com.YCH.user.controller.v1;

import com.YCH.apis.user.apis.UserRelationControllerApi;
import com.YCH.model.common.dtos.ResponseResult;
import com.YCH.model.user.dtos.UserRelationDto;
import com.YCH.user.service.AppLoadArticleAuthorService;
import com.YCH.user.service.AppUserRelationService;
import com.YCH.utils.common.IdsUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/user")
public class UserRelationController implements UserRelationControllerApi {
    @Autowired
    private AppUserRelationService appUserRelationService;
    @Autowired
    private AppLoadArticleAuthorService appLoadArticleAuthorService;

    @Override
    @PostMapping("/user_follow")
    public ResponseResult follow(@RequestBody UserRelationDto dto){
        return appUserRelationService.follow(dto);
    }

    @Override
    @GetMapping("/load_author")
    public ResponseResult loadAuthor(@RequestParam(value = "articleId")String articleId) {
        Long articleID = null;
        try{
            articleID = IdsUtils.decryptLong(articleId);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return appLoadArticleAuthorService.loadAuthor(articleID);
    }
}